package com.atguigu.spring6.resource;

import org.springframework.core.io.FileSystemResource;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

//访问系统中的资源
public class FileSystemResourceDemo {
    public static void main(String[] args) {
        loadFileResource("D:\\12.txt");
    }

    public static void loadFileResource(String path) {
        //1.创建FileSystemResource对象
        FileSystemResource resource = new FileSystemResource(path);
        //2.通过FileSystemResource对象获取文件对应的File对象
        File file = resource.getFile();

        System.out.println(resource.getFilename());
        System.out.println(resource.getDescription());

        try {
            InputStream in = resource.getInputStream();
            byte[] b = new byte[1024];
            while (in.read(b) != -1) {
                System.out.println(new String(b));
            }
        } catch (IOException e) {

            throw new RuntimeException(e);
        }

    }
}
